package edu.xidian.bdilab.jrbigdata.controller.bank;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.service.bank.register.BankRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName BankRegisterController
 * @Description TODO
 * @Author tuantuan
 * @Date 2019/3/28 下午7:34
 * @Version 1.0
 * @Attention Copyright (C), 2004-2019, BDILab, XiDian University
 **/
@RestController
@Api(tags = {"bankRegister-金融机构注册功能"})
public class BankRegisterController {
    @Autowired
    BankRegisterService bankRegisterService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankId", value = "银行行号"),
            @ApiImplicitParam(name = "fkUserName", value = "金融机构用户名"),
            @ApiImplicitParam(name = "bankName", value = "银行名称"),
            @ApiImplicitParam(name = "regin", value = "所属区域(枚举)"),
            @ApiImplicitParam(name = "street", value = "街道/乡镇"),
            @ApiImplicitParam(name = "contactName", value = "联系人姓名"),
            @ApiImplicitParam(name = "contactPhone", value = "联系人手机号"),
            @ApiImplicitParam(name = "password", value = "密码"),
            @ApiImplicitParam(name = "description", value = "机构介绍")
    })
    @RequestMapping(value = "bank/register", method = RequestMethod.POST)
    public ResponseResult register(@RequestParam int bankId,
                                   @RequestParam String fkUserName,
                                   @RequestParam String bankName,
                                   @RequestParam int regin,
                                   @RequestParam String street,
                                   @RequestParam String contactName,
                                   @RequestParam String contactPhone,
                                   @RequestParam String password,
                                   @RequestParam String description
                                   ){
        ResponseResult responseResult = new ResponseResult();

        if (bankRegisterService.checkBankId(bankId) == false){
            responseResult.setSuccess(false);
            responseResult.setCode(BankCode.REGISTER_FAIL_BANKID.getCode());
            responseResult.setMessage(BankCode.REGISTER_FAIL_BANKID.getMessage());
            return responseResult;
        }else if (bankRegisterService.checkUserName(fkUserName) == false){
            responseResult.setSuccess(false);
            responseResult.setCode(BankCode.REGISTER_FAIL_USERNAME.getCode());
            responseResult.setMessage(BankCode.REGISTER_FAIL_USERNAME.getMessage());
            return responseResult;
        }else {

            bankRegisterService.setBankInfo(bankId, bankName, regin, street, contactName, contactPhone,fkUserName,description);
            bankRegisterService.setBankUser(fkUserName, password);

            responseResult.setSuccess(true);
            responseResult.setCode(BankCode.REGISTER_SUCCESS.getCode());
            responseResult.setMessage(BankCode.REGISTER_SUCCESS.getMessage());
        }

        return responseResult;

    }
}
